// /common/http.api.js

// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
let hotSearchUrl = '/api/index/';
let indexUrl = '/api/index/';
let loginUrl ='/api/auth/login';
let denglu ='/api/user';
let zhuc = '/api/auth/register';
let xgnc = '/api/user';
let loginout = '/api/auth/logout';
let token = '/api/auth/oss/token';
let touxiang = '/api/user/avatar';
//let xiangq = ``;


// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 此处没有使用传入的params参数
	let getSearch = (params = {}) => vm.$u.get(hotSearchUrl,params);
		
	
	
	// 此处使用了传入的params参数，一切自定义即可
	let getInfo = (params = {}) => vm.$u.post(indexUrl, params);
	
	//登录接口
	
	let login = (params ={}) => vm.$u.post(loginUrl,params);
	
	//用户信息接口
	
	let user = () => vm.$u.get(denglu);
	
	//注册接口
	
	let zc = (params ={}) => vm.$u.post(zhuc,params);
	
	//修改用户信息
	
	let xgyh = (params ={}) => vm.$u.put(xgnc,params);
	
	//退出登录
	
	let tuichu = () => vm.$u.post(loginout);
	//获取oss token 
	
	let ossToken = () => vm.$u.get(token);
	
	//更新头像api
	
	let tx = (params ={}) => vm.$u.patch(touxiang,params);
	
	// 商品详情api 
	
	let xq = (id = {}) => vm.$u.get(`/api/goods/${id}`);
	
	// 收藏api
	
	let sc = (id ={}) => vm.$u.post(`/api/collects/goods/${id}`);
	
	// 购物车api
	
	let gwc = (params ={}) => vm.$u.post(`/api/carts`,params);
	
	//购物车列表
	
	let gwclb  = () => vm.$u.get('/api/carts');
	
	//商品api
	
	let shangp = (params ={}) => vm.$u.get('/api/goods',params);
	
	// 购物车列表数据
	
	let gwclbsj = (id ={}) => vm.$u.get(`/api/carts?include=${id}`);
	
	
	
	
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {getSearch, getInfo,login,user,zc,xgyh,tuichu,ossToken,tx,xq,sc,gwc,gwclb,shangp,gwclbsj};
}
export default {
	install
}